package main

import (
	"fmt"
	"gopool/pool"
	"sync"
	"time"
)

var j int64

func main() {

	startTime := time.Now().UnixNano()

	var wg sync.WaitGroup
	pl := &pool.Pool{
		Capacity:   10,
		FreeSignal: 0,
		Release:    make(chan pool.Sig, 1),
	}

	pl.Cond = sync.NewCond(&pl.Lock)

	for i := 0; i < 10000000; i++ {
		wg.Add(1)
		_ = pl.Submit(func() {

			fmt.Println(j)
			j++
			//time.Sleep(time.Second * 2)
			wg.Done()
		})
	}
	wg.Wait()

	fmt.Printf("cap:%d", pl.Capacity)
	fmt.Printf("running :%d\n", pl.Running)

	/* 程序主体 */

	endTime := time.Now().UnixNano()
	seconds := float64((endTime - startTime) / 1e9)

	fmt.Println(seconds)

}
